package com.torry.edss.domain.accessor.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.torry.edss.domain.model.LimitUp;
import com.torry.edss.infras.entity.LimitBombDO;
import com.torry.edss.domain.model.LimitBomb;
import com.torry.edss.infras.entity.LimitUpDO;
import com.torry.edss.infras.mapper.LimitBombMapper;
import com.torry.edss.domain.accessor.LimitBombAccessor;
import org.springframework.stereotype.Service;
import com.torry.boot.starter.mybatisplus.service.AccessorImpl;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author torry.wang
 * @since 2025-05-09
 */
@Service
@SuppressWarnings("DuplicatedCode")
public class LimitBombAccessorImpl extends AccessorImpl<LimitBombMapper, LimitBombDO, LimitBomb> implements LimitBombAccessor {
    @Override
    public LimitBomb toModel(LimitBombDO entity) {
        if (entity == null) return null;
        LimitBomb limitBomb = new LimitBomb();
        limitBomb.setDate(entity.getDate());
        limitBomb.setCompanyId(entity.getCompanyId());
        limitBomb.setPrice(entity.getPrice());
        limitBomb.setLimitPrice(entity.getLimitPrice());
        limitBomb.setUpPercentage(entity.getUpPercentage());
        limitBomb.setTransactionAmount(entity.getTransactionAmount());
        limitBomb.setMarketValue(entity.getMarketValue());
        limitBomb.setTurnoverPercentage(entity.getTurnoverPercentage());
        limitBomb.setStat(entity.getStat());
        limitBomb.setFirstLimitTime(entity.getFirstLimitTime());
        limitBomb.setBombCount(entity.getBombCount());
        limitBomb.setQuantity(entity.getQuantity());
        limitBomb.setPreviousDayQuantity(entity.getPreviousDayQuantity());
        limitBomb.setId(entity.getId());
        limitBomb.setCreateTime(entity.getCreateTime());
        limitBomb.setUpdateTime(entity.getUpdateTime());
        limitBomb.setNextDayOpenUpPercentage(entity.getNextDayOpenUpPercentage());
        return limitBomb;
    }

    @Override
    public LimitBombDO toEntity(LimitBomb model) {
        if (model == null) return null;
        LimitBombDO limitBombDO = new LimitBombDO();
        limitBombDO.setDate(model.getDate());
        limitBombDO.setCompanyId(model.getCompanyId());
        limitBombDO.setPrice(model.getPrice());
        limitBombDO.setLimitPrice(model.getLimitPrice());
        limitBombDO.setUpPercentage(model.getUpPercentage());
        limitBombDO.setTransactionAmount(model.getTransactionAmount());
        limitBombDO.setMarketValue(model.getMarketValue());
        limitBombDO.setTurnoverPercentage(model.getTurnoverPercentage());
        limitBombDO.setStat(model.getStat());
        limitBombDO.setFirstLimitTime(model.getFirstLimitTime());
        limitBombDO.setBombCount(model.getBombCount());
        limitBombDO.setQuantity(model.getQuantity());
        limitBombDO.setPreviousDayQuantity(model.getPreviousDayQuantity());
        limitBombDO.setId(model.getId());
        limitBombDO.setCreateTime(model.getCreateTime());
        limitBombDO.setUpdateTime(model.getUpdateTime());
        limitBombDO.setNextDayOpenUpPercentage(model.getNextDayOpenUpPercentage());
        return limitBombDO;
    }

    @Override
    public int countByDate(String date) {
        return this.count(new LambdaQueryWrapper<LimitBombDO>().eq(LimitBombDO::getDate, date));
    }

    @Override
    public int countByDateAndCompanyId(String date, Long companyId) {
        return this.count(new LambdaQueryWrapper<LimitBombDO>().eq(LimitBombDO::getDate, date).eq(LimitBombDO::getCompanyId, companyId));
    }

    @Override
    public List<LimitBomb> findByDate(String date) {
        return this.list(new LambdaQueryWrapper<LimitBombDO>().eq(LimitBombDO::getDate, date));
    }
}
